{extend name="index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">工单管理</div>
    <div class="layui-card-body">
        <div class="layui-form">
            <table class="layui-hide" id="currentTable" lay-filter="currentTable"></table>
            <script type="text/html" id="barTool">
                <a data-id='{{ d.id }}' class="layui-btn layui-btn-xs start" title="开始">开始</a>
                <a data-id='{{ d.id }}' class="layui-btn layui-btn-xs chehui" title="撤回">撤回</a>
                <a data-id='{{ d.id }}' class="layui-btn layui-btn-xs over " title="结束">结束</a>
                <a href='{:url("delete")}?id={{ d.id }}' class="layui-btn layui-btn-xs layui-tr-del" title="取消">取消</a>
                <a data-open='{:url("edit")}?id={{ d.id }}' class="layui-btn layui-btn-xs" title="打印">打印</a>
                <a data-open='{:url("copy")}?id={{ d.id }}' class="layui-btn layui-btn-xs" title="复制">复制</a>
                <a href='{:url("delete")}?id={{ d.id }}' class="layui-btn layui-btn-danger layui-btn-xs layui-tr-del">删除</a>
            </script>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
layui.use(['yznTable','jquery'], function() {
    var table = layui.yznTable;
    var $ = layui.jquery;

    var init = {
        table_elem: '#currentTable',
        add_url: "{:url('add')}",
    };
    //开始任务的逻辑
    $('body').on('click','.start',function(){
        var id = $(this).attr('data-id');
        $.post('{:url("start")}',{id:id},function(res){
            // layer.msg('开始成功');
            layer.msg('开始中', {icon: 16,time:500},function(){
                if(res.code > 0){
                    layer.msg('开始成功',{icon: 1});
                }else{
                    layer.msg(res.msg,{icon: 2});
                }
                tableIns.reload()
            });
        },'json');
    })
    //撤回
    $('body').on('click','.chehui',function(){
        var id = $(this).attr('data-id');
        $.post('{:url("chehui")}',{id:id},function(res){
            // layer.msg('开始成功');
            layer.msg('撤回中', {icon: 16,time:500},function(){
                if(res.code > 0){
                    layer.msg('撤回成功',{icon: 1});
                }else{
                    layer.msg(res.msg,{icon: 2});
                }
                tableIns.reload()
            });
        },'json');
    })
    //结束
    $('body').on('click','.over',function(){
        var id = $(this).attr('data-id');
        $.post('{:url("over")}',{id:id},function(res){
            // layer.msg('开始成功');
            layer.msg('撤回中', {icon: 16,time:500},function(){
                if(res.code > 0){
                    layer.msg('结束成功',{icon: 1});
                }else{
                    layer.msg(res.msg,{icon: 2});
                }
                tableIns.reload()
            });
        },'json');
    })
    var tableIns = table.render({
        init: init,
        id:'currentTable',
        elem: '#currentTable',
        toolbar: ['refresh','add'],
        url: '{:url("index")}',
        search:true,
        cols: [
            [
                { field: 'id',width:80, title: '序号'},
                { field: 'nums',width:100,  align: 'left', title: '工单编号'},
                { field: 'product_nums',width:100, title: '产品编号' },
                { field: 'product_title',width:100, title: '产品名称' },
                { field: 'product_guige',width:100, title: '产品规格' },
                { field: 'product_danwei',width:100, title: '单位' },
                { field: 'status_msg',width:100, title: '状态' },
                { field: 'begin_time',width:200, title: '计划开始时间' },
                { field: 'end_time',width:200, title: '计划结束时间' },
                { field: 'total',width:100, title: '计划数' },
                { field: 'actual_nums',width:100, title: '实际数' },
                { field: 'good',width:80, title: '良品数' },
                { field: 'bad',width:80, title: '不良品数' },
                { field: 'admin', width:300,title: '生产进度' },
                { field: 'add_admin',width:100, title: '创建人' },
                { field: 'up_admin',width:100, title: '修改人' },
                { field: 'actual_begin_time',width:200, title: '实际开始时间' },
                { field: 'actual_end_time',width:200, title: '实际结束时间' },
                { field: 'addtime', width:200,title: '创建时间' },
                { field: 'bz', width:100,title: '备注' },
                { fixed: 'right', width: 350, title: '操作', toolbar: '#barTool' }
            ]
        ],
        page:{},
    });
});
</script>
{/block}